<?php

namespace App\Admin\Forms;

use Dcat\Admin\Widgets\Form;

class Setting extends Form
{
    /**
     * Handle the form request.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {
        // dump($input);
        admin_setting($input);
        // return $this->response()->error('Your error message.');

        return $this
            ->response()
            ->success('设置成功.')
            ->refresh();
    }

    /**
     * Build a form here.
     */
    public function form()
    {
        $this->text('appid', 'Appid')->required();
        $this->text('mch_id', '微信支付商户号')->required();
        $this->text('key', 'API密钥(key)')->required();
        $this->text('app_secret', 'AppSecret')->required();
    }

    /**
     * The data of the form.
     *
     * @return array
     */
    public function default()
    {
        return [
            'appid' => admin_setting('appid'),
            'mch_id' => admin_setting('mch_id'),
            'key' => admin_setting('key'),
            'app_secret' => admin_setting('app_secret'),
        ];
    }
}
